package com.baidu.bm.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.baidu.bm.model.Book;
import com.baidu.bm.service.BookService;

/**
 * 书籍控制器. 负责执行所有与书相关的页面业务逻辑.
 * 
 * @author GuoLin
 * 
 */
@Controller
@RequestMapping("/books")
public class BookController {

	@Autowired
	private BookService bookService;

	public BookService getBookService() {
		return bookService;
	}

	public void setBookService(BookService bookService) {
		this.bookService = bookService;
	}

	@RequestMapping
	public String index() {
		return "redirect:/books/list";
	}

	@RequestMapping("/list")
	public ModelAndView list() {
		ModelAndView mav = new ModelAndView();
		return mav;
	}

	@RequestMapping("/bookcaselist")
	public ModelAndView bookcaselist() {
		List<Book> allBooks = bookService.getAllBooks();
		ModelAndView mav = new ModelAndView();
		mav.addObject("allBooks", allBooks);
		return mav;
	}
}
